package main

import (
	"github.com/panjf2000/ants/v2"
	"log"
	"sync"
	"time"
)

func main() {

	start := time.Now().UnixNano()
	// 清理线程池
	defer ants.Release()

	pool, err := ants.NewPool(20)
	if err != nil {
		panic(err)
		return
	}

	wg := sync.WaitGroup{}
	task := func() {
		log.Println(1111)
		wg.Done()
	}
	for i := 0; i < 1000; i++ {
		pool.Submit(task)
		wg.Add(1)
	}

	wg.Wait()

	end := time.Now().UnixNano()

	diff := end - start

	log.Println("start:", start)
	log.Println("end:", diff)
	log.Println("执行完成:", diff)
}
